package com.easylinkin.linkappapi.airconditioner.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.airconditioner.entity.AirDevice;
import com.easylinkin.linkappapi.airconditioner.entity.AirMonitorQuery;
import com.easylinkin.linkappapi.airconditioner.service.AirMonitorService;
import com.easylinkin.linkappapi.common.model.RequestModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * class info :空调监控功能
 *
 * @author liuqihang
 * @date 2021/5/8 11:07
 */
@RestController
@RequestMapping("/airMonitor")
@Slf4j
public class AirMonitorController {

    @Autowired
    private AirMonitorService airMonitorService;

    //获取空调监控列表
    @PostMapping("getAirDevicePage")
    public RestMessage getAirDevicePage(@RequestBody RequestModel<AirMonitorQuery> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<AirDevice> record = airMonitorService.getAirDevicePage(requestModel.getPage(), requestModel.getCustomQueryParams());
        if(record == null){
            return RestBuilders.successBuilder().message("暂无数据,请核对是否有空间区域绑定").build();
        }
        return RestBuilders.successBuilder().data(record).build();
    }

    @PostMapping("/getAirConditionStatistic")
    public RestMessage countDeviceByOnlineState(@RequestBody AirMonitorQuery amq) {
        return RestBuilders.successBuilder().data(airMonitorService.getAirConditionStatistic(amq)).build();
    }
}
